package com.clk.portfoy.complib.portfoy;

import javax.swing.DefaultListModel;

import com.clk.desktop.gui.components.basic.ClkList;
import com.clk.portfoy.PortfoyStatics;
import com.clk.portfoy.classlib.portfoy.AbsDeger;

public class ClkPortfoyList extends ClkList {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	// ---------------------------------------------------------------------------------
	@SuppressWarnings("rawtypes")
	public ClkPortfoyList() {
		super(new DefaultListModel());
		refresh();
	}

	// ---------------------------------------------------------------------------------
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void refresh() {
		DefaultListModel listModel = new DefaultListModel();
		for (AbsDeger deger : PortfoyStatics.PORTFOY.getDegerler()) {
			listModel.addElement(new PortfoyListItem(deger));
		}
		this.setModel(listModel);
	}

	// ---------------------------------------------------------------------------------

	public AbsDeger getSelectedDegerValue() {
		// TODO Auto-generated method stub
		if (this.getSelectedValue() != null) {
			return ((PortfoyListItem) this.getSelectedValue()).getDeger();
		}
		return null;
	}
	// ---------------------------------------------------------------------------------
}

// *******************************************************************************
class PortfoyListItem {
	private AbsDeger itemDeger;

	// ---------------------------------------------------------------------------------
	public PortfoyListItem(AbsDeger itemDeger) {
		this.itemDeger = itemDeger;
	}

	// ---------------------------------------------------------------------------------
	public AbsDeger getDeger() {
		return this.itemDeger;
	}

	// ---------------------------------------------------------------------------------
	public String toString() {
		return itemDeger.getIsim();
	}
	// ---------------------------------------------------------------------------------
}
// *******************************************************************************